package server;

import server.conf.Service;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author bwcx_jzy
 * @since 2021/11/19
 */
public class SocketAccept implements Runnable {
    private final Service service;
    private final ServerSocket serverSocket;

    public SocketAccept(Service service, ServerSocket serverSocket) {
        this.service = service;
        this.serverSocket = serverSocket;
    }

    @Override
    public void run() {
        // 多线程改造（使用线程池）
        while (true) {
            Socket socket;
            try {
                socket = serverSocket.accept();
            } catch (IOException e) {
                e.printStackTrace();
                continue;
            }
            RequestProcessor requestProcessor = new RequestProcessor(socket, service);
            //requestProcessor.start();
            Bootstrap.getThreadPoolExecutor().execute(requestProcessor);
        }
    }
}
